<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: AdminviewwidgetController.php 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
//GET CONTENT TABLE
$tableContent = Engine_Api::_ ()->getDbtable ( 'content', 'core' );

//GET CONTENT TABLE NAME
$tableContentName = $tableContent->info ( 'name' );

$tableName = Engine_Api::_ ()->getDbtable ( 'pages', 'core' );

//GET WIDGETIZED PAGE INFORMATION
$selectPage = Engine_Api::_ ()->sitepage ()->getWidgetizedPage ();

if (empty ( $selectPage )) {
	$pageCreate = $tableName->createRow ();
	$pageCreate->name = 'sitepage_index_view';
	$pageCreate->displayname = 'Page Profile';
	$pageCreate->title = 'Page Profile';
	$pageCreate->description = 'This is the page view  page.';
	$pageCreate->custom = 1;
	$page_id = $pageCreate->save ();
} else {
	$page_id = $selectPage->page_id;
}

if (! empty ( $page_id )) {
	$tableContent->delete ( array ('page_id =?' => $page_id ) );
	//INSERT MAIN CONTAINER
	$mainContainer = $tableContent->createRow ();
	$mainContainer->page_id = $page_id;
	$mainContainer->type = 'container';
	$mainContainer->name = 'main';
	$mainContainer->order = 2;
	$mainContainer->save ();
	$container_id = $mainContainer->content_id;
	
	//INSERT MAIN-MIDDLE CONTAINER
	$mainMiddleContainer = $tableContent->createRow ();
	$mainMiddleContainer->page_id = $page_id;
	$mainMiddleContainer->type = 'container';
	$mainMiddleContainer->name = 'middle';
	$mainMiddleContainer->parent_content_id = $container_id;
	$mainMiddleContainer->order = 6;
	$mainMiddleContainer->save ();
	$middle_id = $mainMiddleContainer->content_id;
	
	//INSERT MAIN-LEFT CONTAINER
	$mainLeftContainer = $tableContent->createRow ();
	$mainLeftContainer->page_id = $page_id;
	$mainLeftContainer->type = 'container';
	$mainLeftContainer->name = 'left';
	$mainLeftContainer->parent_content_id = $container_id;
	$mainLeftContainer->order = 4;
	$mainLeftContainer->save ();
	$left_id = $mainLeftContainer->content_id;
	$showmaxtab = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.showmore', 8 );
	
	//INSERT MAIN-MIDDLE-TAB CONTAINER
	$middleTabContainer = $tableContent->createRow ();
	$middleTabContainer->page_id = $page_id;
	$middleTabContainer->type = 'widget';
	$middleTabContainer->name = 'core.container-tabs';
	$middleTabContainer->parent_content_id = $middle_id;
	$middleTabContainer->order = 7;
	$middleTabContainer->params = "{\"max\":\"$showmaxtab\"}";
	$middleTabContainer->save ();
	$middle_tab = $middleTabContainer->content_id;
	
	//INSERTING THUMB PHOTO WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.thumbphoto-sitepage', $middle_id, 1 );
	
	//INSERTING TITLE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.title-sitepage', $middle_id, 2 );
	
	//INSERTING LIKE WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.page-like-button', $middle_id, 3 );
	
	//INSERTING FACEBOOK LIKE WIDGET
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'facebookse' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'Facebookse.facebookse-sitepageprofilelike', $middle_id, 4 );
	}
	
	//INSERTING PHOTO STRIP WIDGET
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.photorecent-sitepage', $middle_id, 5 );
	}
	
	//INSERTING MAIN PHOTO WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.mainphoto-sitepage', $left_id, 10 );
	
	//INSERTING OPTIONS WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.options-sitepage', $left_id, 11 );
	
	//INSERTING INFORMATION WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.information-sitepage', $left_id, 14, 'Information', 'true' );
	
	//INSERTING WRITE SOMETHING ABOUT WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.page-like', $left_id, 15 );
	
	//INSERTING RATING WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagereview' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepagereview.ratings-sitepagereviews', $left_id, 16, 'Ratings' );
	}
	
	//INSERTING BADGE WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagebadge' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepagebadge.badge-sitepagebadge', $left_id, 17, 'Badge' );
	}
	
	//INSERTING YOU MAY ALSO LIKE WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.suggestedpage-sitepage', $left_id, 18, 'You May Also Like' );
	
	//INSERTING SOCIAL SHARE WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.socialshare-sitepage', $left_id, 19, 'Social Share' );
	
	//INSERTING FOUR SQUARE WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.foursquare-sitepage', $left_id, 20 );
	
	//INSERTING INSIGHTS WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.insights-sitepage', $left_id, 21, 'Insights' );
	
	//INSERTING FEATURED OWNER WIDGET 
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.featuredowner-sitepage', $left_id, 22, 'Owners' );
	
	//INSERTING ALBUM WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.albums-sitepage', $left_id, 23, 'Albums' );
	}
	
	//INSERTING PAGE PROFILE PLAYER WIDGET 
	if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' )) {
		Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepagemusic.profile-player', $left_id, 24 );
	}
	
	//INSERTING ALBUM WIDGET   
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.favourite-page', $left_id, 25, 'Linked Pages' );
	
	//INSERTING ACTIVITY FEED WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'socialengineaddon.feed', $middle_tab, 1, 'Updates', 'true' );
	
	//INSERTING INFORAMTION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.info-sitepage', $middle_tab, 2, 'Info', 'true' );
	
	//INSERTING OVERVIEW WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.overview-sitepage', $middle_tab, 3, 'Overview', 'true' );
	
	//INSERTING LOCATION WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'sitepage.location-sitepage', $middle_tab, 4, 'Map', 'true' );
	
	//INSERTING LINKS WIDGET
	Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $tableContent, $tableContentName, $page_id, 'widget', 'core.profile-links', $middle_tab, 125, 'Links', 'true' );
}
?>